## ----------------------------------------------------------------------------
## Title: 01_map.R
## Author: Elsa Voytas
## Created: April-8-2024
## ----------------------------------------------------------------------------

## Producing figure 1 (map of reparations policies)
library(dplyr)
library(readr)
library(ggplot2)
library(maps)
tj <- read_csv("Input/tjet_cy.csv") # Data from Transitional Justice Evaluation Tools (https://transitionaljusticedata.org/en/downloads.html)

world_map <- map_data("world") %>%
  rename(country = region)

sum <- tj %>%
  group_by(country) %>%
  summarise(Reparations = sum(reparations)) %>%
  mutate(Reparations = ifelse(Reparations==0, NA, Reparations))

# times reparations administered
times <- sum(sum$Reparations, na.rm=T) # 79 times

reps.map <- right_join(sum, world_map, by = "country") 

figure1 <- ggplot(reps.map, aes(long, lat, group = group))+
  geom_polygon(aes(fill = Reparations), color = "white")+
  scale_fill_distiller(palette = "Oranges",
                       direction = 1,
                       na.value = "gray95") + theme_minimal() + 
  theme(panel.grid.major =  element_blank(),
        panel.grid.minor = element_blank(),
        axis.title = element_blank(),
        axis.ticks = element_blank(),
        axis.text = element_blank())

ggsave("Output/figure1.jpg", width = 12, height = 7, dpi = 300, bg="white")

print("Figure 1 complete")
